﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Entities;

namespace QLTTTH
{
    public partial class frmThemNhom : DevExpress.XtraEditors.XtraForm
    {
        public frmThemNhom()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private PhanQuyenInfo GetNhomQuyen()
        {
            var nhomQuyen = new PhanQuyenInfo();
            if (!string.IsNullOrEmpty(txtNhomND.Text.Trim()))
            {
                nhomQuyen.MaNhomNguoiDung = int.Parse(txtNhomND.Text);
            }
            if (!string.IsNullOrEmpty(txtNhomQuyen.Text))
            {
                nhomQuyen.MaNhomQuyen = int.Parse(txtNhomQuyen.Text);
            }
            nhomQuyen.TenNhom = txtTenNhom.Text;
            nhomQuyen.MoTa = txtMoTa.Text;
            if (chkTrangThai.Checked)
            {
                nhomQuyen.TrangThai = true;
            }
            else
            {
                nhomQuyen.TrangThai = false;
            }
            return nhomQuyen;
        }

        public delegate void SendData(PhanQuyenInfo pq);

        public SendData sendData;

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (sendData != null)
            {
                sendData(GetNhomQuyen());
                DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        public void FillControl(PhanQuyenInfo pq)
        {
            this.txtNhomND.Text = pq.MaNhomNguoiDung.ToString();
            this.txtNhomQuyen.Text = pq.MaNhomQuyen.ToString() ;
            this.txtTenNhom.Text = pq.TenNhom;
            this.txtMoTa.Text = pq.MoTa;
            this.chkTrangThai.Checked = pq.TrangThai;
        }
    }
}